package 力扣;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yyq
 * @create 2022-06-07 11:24
 */
public class leetcode45 {
    public static void main(String[] args) {
        leetcode45 leetcode45=new leetcode45();
        leetcode45.jump(new int[]{1,2,3});
    }
    public int jump(int[] nums) {
        if(nums.length==1) return 0;
        if(nums.length==2) return 1;
        if(nums[0]>=nums.length-1) return 1;
        int step=0;
        int maxLength = nums[0];

        int beginIndex=0;
        int endValue=0+nums[0];

        while(true){
            if(maxLength>=nums.length-1) return step+1;

            int tempIndex=0;
            for (int i=beginIndex+1;i<=endValue;i++){
                if(nums[i]+i>maxLength){
                    maxLength = nums[i] + i;
                    tempIndex = i;
                }
            }

            beginIndex=tempIndex;
            endValue =beginIndex + nums[beginIndex];
            step++;
        }
    }
}
